-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] Use mapping format for reading date
values
#169
[WIP] Use mapping format for reading date
values
#169
Conversation
Signed-off-by: Yury-Fridlyand <yuryf@bitquilltech.com>
… update tests. Signed-off-by: Yury-Fridlyand <yuryf@bitquilltech.com>
Signed-off-by: Yury-Fridlyand <yuryf@bitquilltech.com>
@@ -57,6 +57,21 @@ public LocalTime timeValue() { | |||
return time; | |||
} | |||
|
|||
@Override | |||
public LocalDate dateValue() { | |||
return LocalDate.now(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was this required for?
It would need to account for query start time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- We return
TIMESTAMP
for OpenSearchdate
type=>
we returnExprTimestampValue
- An index can store time in
date
field=>
parser returnsLocalTime
To satisfy both 1 and 2 we have to build ExprTimestampValue
from LocalTime
which calls to LocalDate.now()
.
I see few ways to fix/avoid this:
- Don't return
ExprTimestampValue
where it is possible. It is nice to have, but still we would have to buildExprTimestampValue
fromLocalTime
. - Change how we build
ExprTimestampValue
fromLocalTime
- use a fixed date (e.g. Epoch) instead of today. - Deliver
queryContext
toOpenSearchExprValueFactory
inopensearch
module.
private final Map<ExprType, BiFunction<Content, MappingEntry, ExprValue>> typeActionMap = | ||
new ImmutableMap.Builder<ExprType, BiFunction<Content, MappingEntry, ExprValue>>() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because MappingEntry
is only used by date time, I'm think can we add this mapping info to Content
?
@AllArgsConstructor | ||
public class MappingEntry { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may need more thoughts about this new abstraction. For now it seems only for OpenSearch date field mapping. Can we extend it to carry mapping info for all OpenSearch fields? For example, multi-field may use this abstraction to get inner field name and type.
{
"mappings": {
"properties": {
"city": {
"type": "text",
"fields": {
"raw": {
"type": "keyword"
}
}
}
}
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, current implementation doesn't work with keyword
and nested
types.
namedAggregatorList.forEach(agg -> builder.put(agg.getName(), new MappingEntry(null, null, agg.type()))); | ||
groupByList.forEach(group -> builder.put(group.getNameOrAlias(), new MappingEntry(null, null, group.type()))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking should we refactor OpenSearchDataType
? Rather than static Enum
, we instantiate it with mapping info for each field during analyzing.
class OpenSearchDataType implements ExprType:
val mappingInfo;
val osTypeName;
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Superseded by #273 |
Signed-off-by: Yury-Fridlyand yuryf@bitquilltech.com
Description
The fix is to collect formats from mapping and pass it to
OpenSearchExprValueFactory
.I added
mapping2
member toIndexMapping
andOpenSearchExprValueFactory
which hold required data. The original mapping is not removed yet to ensure that everything works as was before.Test data
date_formats.json.txt
date_formats_mappings.json.txt
Test queries
For example,
epoch_second
(was reported on forum)Unsupported formats
(see links below)
They fall back to error:
opensearch-project-sql/opensearch/src/main/java/org/opensearch/sql/opensearch/data/value/OpenSearchExprValueFactory.java
Lines 258 to 261 in f335101
Time interpreting issue
opensearch-project-sql/opensearch/src/main/java/org/opensearch/sql/opensearch/data/value/OpenSearchExprValueFactory.java
Line 254 in f335101
goes to
opensearch-project-sql/core/src/main/java/org/opensearch/sql/data/model/ExprTimeValue.java
Line 62 in f335101
There is no option to access queryContext there.
This could be fixed by one of
ExprTimeValue
TBD
LocalTime
?ExprTimestampValue
for date and time columns? Note: ensure that entire column has the same or similar format(s).TODO
SQLCorrectnessIT
with querySELECT Cancelled, AvgTicketPrice, FlightDelayMin, Carrier, timestamp FROM opensearch_dashboards_sample_data_flights
. Test results - Class org.opensearch.sql.sql.SQLCorrectnessIT.pdfWrong data returned for
timestamp
, mapping"format" : "yyyy-MM-dd HH:mm:ss"
Links
Issues Resolved
opensearch-project#794
https://forum.opensearch.org/t/sql-select-fails-on-date-fields-format-epoch-second/11521
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.